package org.jeecg.modules.business.transfer.controller;

import javax.servlet.http.HttpServletRequest;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.system.base.controller.JeecgController;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.modules.business.transfer.entity.PaperWarning;
import org.jeecg.modules.business.transfer.entity.vo.PaperWarningParam;
import org.jeecg.modules.business.transfer.service.IPaperWarningService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.jeecg.common.aspect.annotation.AutoLog;
import org.apache.shiro.authz.annotation.RequiresPermissions;

import java.util.List;

/**
 * @Description: 纸筒库存预警信息
 * @Author: jeecg-boot
 * @Date:   2023-11-10
 * @Version: V1.0
 */
@Api(tags="纸筒库存预警信息")
@RestController
@RequestMapping("/business/paperWarning")
@Slf4j
public class PaperWarningController extends JeecgController<PaperWarning, IPaperWarningService> {
	@Autowired
	private IPaperWarningService paperWarningService;
	
	/**
	 * 分页列表查询
	 *
	 * @param param
	 * @param pageNo
	 * @param pageSize
	 * @return
	 */
	@ApiOperation(value="纸筒库存预警信息-分页列表查询", notes="纸筒库存预警信息-分页列表查询")
	@GetMapping(value = "/list")
	public Result<Page<PaperWarning>> queryPageList(PaperWarningParam param,
													 @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
													 @RequestParam(name="pageSize", defaultValue="10") Integer pageSize) {
		Result<Page<PaperWarning>> result = new Result<Page<PaperWarning>>();
		Page<PaperWarning> pageList = new Page<PaperWarning>(pageNo,pageSize);
		pageList = paperWarningService.pageList(pageList, param);
		result.setSuccess(true);
		result.setResult(pageList);
		return result;
	}
	
	/**
	 *   添加
	 *
	 * @param paperWarning
	 * @return
	 */
	@AutoLog(value = "纸筒库存预警信息-添加")
	@ApiOperation(value="纸筒库存预警信息-添加", notes="纸筒库存预警信息-添加")
	@RequiresPermissions("business:paperWarning:add")
	@PostMapping(value = "/add")
	public Result<String> add(@RequestBody PaperWarning paperWarning) {
		paperWarningService.save(paperWarning);
		return Result.OK("添加成功！");
	}
	
	/**
	 *  编辑
	 *
	 * @param paperWarning
	 * @return
	 */
	@AutoLog(value = "纸筒库存预警信息-编辑")
	@ApiOperation(value="纸筒库存预警信息-编辑", notes="纸筒库存预警信息-编辑")
	@RequiresPermissions("business:paperWarning:edit")
	@PostMapping(value = "/edit")
	public Result<String> edit(@RequestBody PaperWarning paperWarning) {
		paperWarningService.updateById(paperWarning);
		return Result.OK("编辑成功!");
	}
	
	/**
	 *   通过id删除
	 *
	 * @param id
	 * @return
	 */
	@AutoLog(value = "纸筒库存预警信息-通过id删除")
	@ApiOperation(value="纸筒库存预警信息-通过id删除", notes="纸筒库存预警信息-通过id删除")
	@RequiresPermissions("business:paperWarning:delete")
	@DeleteMapping(value = "/delete")
	public Result<String> delete(@RequestParam(name="id",required=true) String id) {
		paperWarningService.removeById(id);
		return Result.OK("删除成功!");
	}
	
	/**
	 * 通过id查询
	 *
	 * @param id
	 * @return
	 */
	@ApiOperation(value="纸筒库存预警信息-通过id查询", notes="纸筒库存预警信息-通过id查询")
	@GetMapping(value = "/queryById")
	public Result<PaperWarning> queryById(@RequestParam(name="id",required=true) String id) {
		PaperWarning paperWarning = paperWarningService.getById(id);
		if(paperWarning==null) {
			return Result.error("未找到对应数据");
		}
		return Result.OK(paperWarning);
	}

	 /**
	  *  批量关闭
	  *
	  * @param ids
	  * @return
	  */
	 @AutoLog(value = "纸筒库存预警信息-批量关闭")
	 @ApiOperation(value="纸筒库存预警信息-批量关闭", notes="纸筒库存预警信息-批量关闭")
	 @RequiresPermissions("business:paperWarning:edit")
	 @PostMapping(value = "/batchClose")
	 public Result<String> batchClose(@RequestBody List<String> ids) {
		 paperWarningService.batchClose(ids);
		 return Result.OK("关闭成功!");
	 }

	/**
	 * 手动触发定时任务
	 *
	 * @return
	 */
	@GetMapping(value = "/generate")
	public Result<Void> generate() {
		paperWarningService.checkSafeInventory();
		return Result.OK();
	}
}
